const {login} = require('./loginOA')
const {autoApprove} = require('./autoApprove');
const url = require("url");
const querystring = require("querystring");

export async function crawler(driver, param) {

  if (!param.jobUrl) {
    console.log('审批地址不能为空')
    return;
  }

  if (!param.loginUrl) {
    console.log('登录地址不能为空')
    return;
  }

  if (!param.driverPath) {
    console.log('驱动路径不能为空')
    return;
  }

  await login(driver, {
    url: param.loginUrl,
    userName: param.userName,
    password: param.password
  })

  let arg = url.parse(param.jobUrl).query;
  let params = querystring.parse(arg);
  console.log(params.jobId)

  await autoApprove(driver, {
    url: param.jobUrl,
    jobType: param.jobType
  })

}
